package com.thd.springboottest.logback.customappender;

import ch.qos.logback.classic.PatternLayout;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.AppenderBase;

import java.util.Properties;

/**
 * com.thd.springboottest.logback.customappender.MyCustomAppender
 *
 * @author: wanglei62
 * @DATE: 2022/4/6 14:40
 **/
public class MyCustomAppender extends AppenderBase<ILoggingEvent> {
    private String brokerList;
    private String topic;
    private String config;
    private PatternLayout layout;
    public MyCustomAppender() {
    }
    @Override
    public void start() {
        super.start();
        Properties props = new Properties();
        System.out.println(this.brokerList);
        System.out.println(this.topic);
        props.put("brokerList",this.brokerList);
        props.put("topic",this.topic);
        this.config = this.brokerList + "-" + this.topic;

    }

    private String subAppend(ILoggingEvent event) {
        return this.layout.doLayout(event);
    }

    @Override
    protected void append(ILoggingEvent event) {
        System.out.println(this.config);
        String message = event.getMessage();
        System.out.println("myCustomAppender write : " + this.subAppend(event));
    }

    public String getBrokerList() {
        return brokerList;
    }

    public void setBrokerList(String brokerList) {
        this.brokerList = brokerList;
    }

    public String getTopic() {
        return topic;
    }

    public void setTopic(String topic) {
        this.topic = topic;
    }

    public String getConfig() {
        return config;
    }

    public void setConfig(String config) {
        this.config = config;
    }

    public PatternLayout getLayout() {
        return layout;
    }

    public void setLayout(PatternLayout layout) {
        this.layout = layout;
    }
}
